// SerialWorker.h
#ifndef SERIALWORKER_H
#define SERIALWORKER_H
#include <QObject>
#include <QSerialPort>
#include <QTimer>
#include <QMutex>
class SerialWorker : public QObject
{
    Q_OBJECT
public:
    explicit SerialWorker(QObject *parent = nullptr);
    void start(QSerialPort *port);
signals:
    void newDataAvailable(const QList<int>& yList);

    void dataReceived(const QString &data);



public slots:
    void readData();
    //定时检测串口（意外断开则重新链接）
    void checkSerialPort1();
    // 检测按钮是否按下
    void updateBtnOnOff(bool state);

private:
    QSerialPort *serialPort;
    QByteArray buffer;
    // 定时器
    QTimer *serialCheckTimer;
    bool btn_on_off;
    QMutex mutex;


};

#endif // SERIALWORKER_H
